const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')


module.exports = {
  entry: './src/main.js',
  output: {
    filename: '[name].js',
    path:path.resolve(__dirname, 'dist')
  },
  devtool: 'source-map',
  devServer: {
    contentBase: './dist'
  },
  module: {
    rules: [
      // {
      //   test: /.js$/,
      //   use: {
      //     loader: 'babel-loader',
      //     options: {
      //       presets: ['@babel/preset-env']
      //     }
      //   }
      // },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/, 
        exclude: /node_modules/, 
        use: 'eslint-loader',
        enforce: "pre"
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.less$/,
        use: [
          'style-loader','css-loader','less-loader'
        ]
      },
      {
        test: /\.(png|jpe?g|gif)$/,
        use: {
          loader: 'file-loader',
          options: {
            outputPath: 'img',
            name: '[name].[ext]'
          }
        }
      }
    ]
  },
  plugins: [
    //new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: 'Webpack Tutorial',
      template: path.join(__dirname,'public/index.html'),
      publicPath:path.join(__dirname,'/dist')
    }),
    new VueLoaderPlugin(),
    //new webpack.HotModuleReplacementPlugin()
    new webpack.DefinePlugin({
      BASE_URL: '"/"'
    })
  ]
  // resolve:{
  //   extensions:['.vue','.js'],
  //   alias:{
  //       'vue$': 'vue/dist/vue.esm.js'
  //   }
  // }
}
